import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'
Vue.use(Vuex)
const vuexLocal = new VuexPersistence({
    storage: {
        getItem: key => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: key => uni.removeStorageSync(key),
        clear: () => uni.clearStorageSync(),
    }
})
const store = new Vuex.Store({
    plugins: [vuexLocal.plugin],
    state: {
        wechatInfo: {},
        userInfo: {}
    },
    mutations: {
		commitClear(state, opts) {
		   state.wechatInfo={}
		   state.userInfo={}
		},
        commitWechatInfo(state, wechatInfo) {
            state.wechatInfo = wechatInfo
        },
        commitUserInfo(state, userInfo) {
            state.userInfo = userInfo
        },
    },
    actions: {
        dispatchUserInfo: ({
            state,
            commit
        }, opts) => {
            commit('commitUserInfo', opts)
        }
    }
})

export default store
